package com.zh.mediaservice.controller.User;

import com.zh.mediacommon.result.Result;
import com.zh.mediapojo.vo.ChatDoctorVO;
import com.zh.mediapojo.vo.ChatPageVO;
import com.zh.mediapojo.vo.DoctorVO;
import com.zh.mediaservice.AiBigModel.DeepSeek;
import com.zh.mediaservice.AiBigModel.SparkLIte;
import com.zh.mediaservice.AiBigModel.SparkUltra;
import com.zh.mediaservice.service.ReserveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/answer")
@Slf4j
public class AnswerController {

    @Autowired
    private SparkUltra sparkUltra;
    @Autowired
    private SparkLIte sparkLIte;
    @Autowired
    private ReserveService reserveService;
    @Autowired
    private DeepSeek deepSeek;

    /**
     * 发送问题
     *
     * @param question 问题
     * @return 星火大模型的回答
     */
    @GetMapping("/ai/sendQuestion/{id}/{question}")
    @Cacheable(value = "AI::deepseek-1.5",key ="#question")
    public Result sendQuestion(@PathVariable("question") String question,@PathVariable("id") Integer uid) {

        //讯飞
//        if(sparkLIte.getIsMediaQuestion(question))
//            return Result.success(sparkUltra.getResponse(question,uid));
//        return Result.success("抱歉，我只能回答和医疗相关的问题");
 //       deepseek
        return Result.success(deepSeek.getAnswer(question).replaceAll("<br>","\n").replaceAll("\\*",""));
    }

    @GetMapping("/doctorList/{description}")
    public Result getDoctorList(@PathVariable String description){
        log.info("description {}",description);
        List<DoctorVO> doctorList = reserveService.getDoctorList(description);

        return Result.success(doctorList);
    }

    @GetMapping("/historyChat/{page}/{pageSize}/{userId}/{doctorId}")
    public Result getHistoryChat(@PathVariable("page") Integer page,@PathVariable("pageSize") Integer pageSize,@PathVariable("userId") Integer userId,@PathVariable("doctorId") Integer doctorId){
        ChatPageVO pageVo = reserveService.getHistoryChat(page, pageSize, userId, doctorId);
        return Result.success(pageVo);
    }

    @GetMapping("/getChatedDoctor/{uid}")
    public Result getChatedDoctor(@PathVariable("uid") Long uid){
        List<ChatDoctorVO> doctorList = reserveService.getChatedDoctor(uid);
        return Result.success(doctorList);
    }
}

